package slash;

import org.newdawn.slick.*;
import org.newdawn.slick.tiled.*;

import slash.constants.Globals;
import slash.entities.EntityManager;
import slash.util.ControlHandler;
import slash.world.*;

public class MainGame extends BasicGame{
	
	private static MainGame instance = null;
	
	/* the map */
	private static World world;
	private static EntityManager entityManager;
	private boolean[][] blocked;
	private static final int SIZE = 34;
	
	private static boolean DEBUG = false;
	
	public MainGame(){
		super("Atlas1");
	}
	
	public static void main(String[] args) throws SlickException
	{
            AppGameContainer app = new AppGameContainer(new MainGame());
            app.setDisplayMode(600, 400, false);
            app.start();
	}
	
	@Override
    public void init(GameContainer container) throws SlickException
    {
		instance = new MainGame();
		
		// creates/initializes the world
		world = new World();
		// creates the player entity
		entityManager = new EntityManager();
		
		toggleDEBUG(true);
    }

    @Override
    /***
     * Updates the current state of the game
     * param: game container, time since last update
     */
    public void update(GameContainer container, int delta) throws SlickException
    {	
    	world.getCurrentMap().update(container, delta);
    	entityManager.PLAYER.update(container, delta);
    }

    @Override
    public void render(GameContainer container, Graphics g) throws SlickException
    {
    	// renders current map with all objects
    	world.getCurrentMap().render(g);
    	
    	entityManager.PLAYER.render(g);
    	// render DEBUG
    }
    
    /**
     * Returns whether debug
     * is enabled or disabled
     */
    public static boolean debug(){
    	return DEBUG;
    }
    
    /**
     * Sets debug to boolean
     */
    public static void toggleDEBUG(boolean b){
    	DEBUG = b;
    }
    
    public static EntityManager getEntityManager(){
    	return entityManager;
    }
    
    public static World getWorld(){
    	return world;
    }
    
    public static MainGame getInstance(){
    	if(instance == null){
    		instance = new MainGame();
    	}
    	return instance;
    }

}
